package com.wc.alorithm_blue_bridge._动态规划.线性DP.奖杯排列;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/12/19 16:15
 * @description
 * https://www.lanqiao.cn/problems/20089/learning/?contest_id=229
 */
public class Main {
    /**
     * 思路：
     * >= 1 的个数, >= 2 的个数都得记得
     * >= 1 的个数, 只能由自己转移
     * >= 2 的个数是从 >= 1的个数转移过来
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010, P = (int)1e9 + 7;
    // f1[key] = value, key 结尾的, 个数 > 1的数量, f2[key] = value, key 结尾的, 个数 > 2的数量
    static Map<Integer, Integer> f1 = new HashMap<>(), f2 = new HashMap<>();
    static int[] a = new int[N];
    static int n, k;

    public static void main(String[] args) {
        n = sc.nextInt();
        k = sc.nextInt();
        for (int i = 0; i < n; i++) a[i] = sc.nextInt();
        for (int i = 0; i < n; i++) {
            int prev = a[i] - k;
            // 新增的
            int new1 = f1.getOrDefault(prev, 0);
            int new2 = f2.getOrDefault(prev, 0);
            // 原始的
            int old1 = f1.getOrDefault(a[i], 0);
            int old2 = f2.getOrDefault(a[i],  0);
            // +1 表示他自己
            long v1 = ((long) new1 + old1 + 1) % P;
            long v2 = ((long) new1 + old2) % P;
            f1.put(a[i], (int)v1);
            f2.put(a[i], (int)v2);
        }
        int res = 0;
        for (int value: f2.values()) res = (res + value) % P;
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

